package com.cy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Usefulness: sca-provider启动类
 * @Author: LeiTing
 * @Date: 2021/9/15  10:43
 * @Version 1.0
 */
@Slf4j
@SpringBootApplication
public class ProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    //@RefreshScope 用于告诉Spring，一旦配置中心数据发生变化
    //自动重新创建它描述的类的实例
    //可用于外部获取类的变化
    @RefreshScope
    @RestController
    public class ProviderController{

        @Value("${server.tomcat.threads.max:200}")
        private Integer maxThread;

        @RequestMapping("/provider/doGetMaxThread")
        public String doGetMaxThread(){
            return "server.threads.max is  "+maxThread;
        }

        //@value用于读取application.yml中的配置
        //要读取的配置需要写在${}这个表达式中
        //${}表达式中":"后的内容为默认值
        @Value("${server.port:8080}")
        private String provider;
        /**
         * 基于此方法实现一个字符串的回显
         * echo:回显的意思
         * rest:一种软件架构编码风格，可以基于这种风格定义url
         * 访问:http://localhost:8081/provider/echo/nacos
         */
        @GetMapping("/provider/echo/{msg}")
        public String doRestEcoh1(@PathVariable("msg") String msg) throws InterruptedException {
//            Thread.sleep(5000);
            log.info("doRestEcoh1 start{}",System.currentTimeMillis()); //{}表示占位符
            return provider+" say hello "+msg;
        }
    }
}
